package com.buaa.util;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.buaa.activity.MainActivity;
import com.buaa.activity.QuestionActivity;
import com.buaa.activity.R;
import com.buaa.activity.SearchActivity;

/**
 * Created by Administrator on 2016/4/15.
 */
public class BaseActivity extends AppCompatActivity {

    private TextView headTitle;
    private Button[] btns = new Button[3];
    private Class[] targetActivities = new Class[]{MainActivity.class, QuestionActivity.class, SearchActivity.class};
    private int[] bottomImgs = new int[]{R.drawable.bottombtn01b, R.drawable.bottombtn02b, R.drawable.bottombtn03b};
    private int[] bottomImgsSelected = new int[]{R.drawable.bottombtn01a, R.drawable.bottombtn02a, R.drawable.bottombtn03a};
    private int i;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    protected void init(String title, int index) {
        headTitle = (TextView)findViewById(R.id.head_title);
        headTitle.setText(title);

        btns[0] = (Button) findViewById(R.id.bottombtn_01);
        btns[1] = (Button) findViewById(R.id.bottombtn_02);
        btns[2] = (Button) findViewById(R.id.bottombtn_03);

        for(i=0;i<btns.length;i++) {
            final int temp = i;
            if(index==i) {
                btns[i].setBackgroundResource(bottomImgsSelected[i]);
            }else {
                btns[i].setBackgroundResource(bottomImgs[i]);
                btns[i].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent in = new Intent(BaseActivity.this, targetActivities[temp]);
                        startActivity(in);
                    }
                });
            }
        }
    }
}
